#include<bits/stdc++.h>
using namespace std;
const int maxn=100000;
const int maxm=1000000;
int n,m,L,V,TT;
pair<int,int>rng[maxn+5];
int p[maxn+5];
set<int>S,T;
bool comp(pair<int,int>u,pair<int,int>v){
    if(u.second==v.second){
        return u.first<v.first;
    }
    return u.second<v.second;
}
void Solve(){
    int d,v,a,answer1=0,answer2=0;
    scanf("%d%d%d%d",&n,&m,&L,&V);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&d,&v,&a);
        if(a<0){
            if(v>V){
                rng[i]={d,min(L+1,d+(V*V-v*v+2*a+1)/(2*a))};
            }
            else{
                rng[i]={-1,-2};
            }
        }
        if(a==0){
            if(v>V){
                rng[i]={d,L+1};
            }
            else{
                rng[i]={-1,-2};
            }
        }
        if(a>0){
            if(v>V){
                rng[i]={d,L+1};
            }
            else{
                rng[i]={d+(V*V-v*v)/(2*a)+1,L+1};
                if(rng[i].first>L){
                    rng[i]={-1,-2};
                }
            }
        }
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&p[i]);
        S.insert(p[i]);
    }
    sort(rng+1,rng+n+1,comp);
    for(int i=1;i<=n;i++){
        if(rng[i].first!=-1){
            // cout<<rng[i].first<<" "<<rng[i].second<<endl;
            set<int>::iterator s=S.lower_bound(rng[i].second);
            bool flag1=false;
            if(s!=S.begin()&&(*(--s))>=rng[i].first){
                answer1++;
                flag1=true;
            }
            set<int>::iterator t=T.lower_bound(rng[i].second);
            if(t!=T.begin()&&(*(--t))>=rng[i].first){
                
            }
            else if(flag1){
                answer2++;
                T.insert(*s);
            }
        }
    }
    S.clear();T.clear();
    printf("%d %d\n",answer1,m-answer2);
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&TT);
    while(TT--){
        Solve();
    }
    return 0;
}